class Person {
  //私有属性加下划线
  private _name: string;
  private _age: number;

  constructor(name: string, age: number) {
    this._name = name;
    this._age = age;
  }
  //做一个拦截操作
  set name(newValue: string) {
    this._name = newValue;
  }
  get name() {
    return this._name;
  }

  //这里可以对年龄进行限制,要不然可以直接在外面进行操作
  set age(newValue: number) {
    if (newValue >= 0 && newValue < 200) {
      this._age = newValue;
    }
  }
  get age() {
    return this._age;
  }
}
const p = new Person("why", 100);
p.name = "kobe";
console.log(p.name);

export {};
